package com.zues.thread.method.yield;

import lombok.extern.slf4j.Slf4j;

/**
 * @ClassName Demo1
 * @Description
 *  yield方法测试
 * 调用 yield 会让提示线程调度器让出当前线程对 CPU 的使用
 * @Author zues
 * @Date 2/28/2025 4:29 下午
 * @Version 1.0
 **/
@Slf4j(topic = "c.Demo1")
public class Demo1 {

    public static void main(String[] args) {
        Thread t1 = new Thread(() -> {
            for (int i = 0; i < 30; i++) {
                log.info("{}", i);
                if (i == 15) {
                    log.info("----yield()执行----");
                    Thread.yield();
                }
            }
        }, "t1");
        t1.start();


        Thread t2 = new Thread(() -> {
            for (int i = 0; i < 30; i++) {
                log.info("{}", i);
            }
        }, "t2");
        t2.start();
    }

}
